package common.lvAward
{
	import com.common.queueloader.QueueLoader;
	import com.common.queueloader.QueueLoaderEvent;
	import com.common.queueloader.QueueVo;
	import com.common.utils.Reflection;
	import com.global.GlobalDef;
	import com.greensock.TweenLite;
	import com.liangzhong.constants.TipsConst;
	import com.liangzhong.events.ActivityEvent;
	import com.liangzhong.events.AppEventDispatcher;
	import com.liangzhong.model.AppData;
	import com.liangzhong.model.goods.GoodsManager;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import lz.controls.core.TitleWindow;
	import lz.controls.managers.AnimationManager;
	import lz.controls.managers.TipsManager;

	/**
	 * 等级奖励界面 
	 * @author lake
	 * 
	 */	
	public class LvAwardView extends TitleWindow implements ILvAwardView
	{
		/**
		 *数据 
		 */		
		private var _data :*;
		/**
		 *显示类型 
		 */		
		private var showType :int;
		
		public function LvAwardView()
		{
			super();
		}
		/**
		 *设置数据 
		 * @param value
		 * 
		 */		
		public function set data(value:*):void
		{
			_data = value;
		}
		/**
		 *获取数据 
		 * @return 
		 * 
		 */		
		public function get data():*
		{
			return null;
		}
		/**
		 *初始化 
		 * 
		 */		
		public function initUI(view :Object = null):void
		{
			//初始化宽高
			width = 587;
			height = 388;
			addEvtListener();
		}
		
		private function loadRes():void
		{
			var loader :QueueLoader= new QueueLoader();
			loader.addEventListener(QueueLoaderEvent.QUEUE_COMPLETE,loadCompleteHandler);
			loader.addQueue(new QueueVo("guide_lv_aw"),"res/swf/guide/guide_lv_aw.swf?" + GlobalDef.ReleaseVersion + ".swf");
			loader.queueLoadStart();
		}
		/**
		 * 
		 * 加载完毕
		 */		
		private function loadCompleteHandler(e :Event):void
		{
			showView(showType);
			e.target.removeEventListener(QueueLoaderEvent.QUEUE_COMPLETE,loadCompleteHandler);
		}
		/**
		*显示对应界面 
		* @param type 0 --- 提示5级 5 -- 5级领取 6--10级领取 7---15级领取
		*/	
		public function showView(type :int):void
		{
			showType = type;
			switch(type)
			{
				case 0 :
				{
					_symbolSkin = Reflection.createInstance("com.lz.fb.guide.skin.Lv5_Rm");
					if(_symbolSkin)
					{
						this.addChild(_symbolSkin);
						_symbolSkin.sureBtn.addEventListener(MouseEvent.CLICK,rm_Handler);
						//浅入
						fadeIn();
					}
					else
					{
						loadRes();
					}
					break;
				}
				case 5 :
				{
					_symbolSkin = Reflection.createInstance("com.lz.fb.guide.skin.Lv5_Get");
					if(_symbolSkin)
					{
						this.addChild(_symbolSkin);
						_symbolSkin.getBtn.addEventListener(MouseEvent.CLICK,get_Handler);
						//浅入
						fadeIn();
					}
					else
					{
						loadRes();
					}
					break;
				}
				case 6 :
				{
					_symbolSkin = Reflection.createInstance("com.lz.fb.guide.skin.Lv10_Get");
					if(_symbolSkin)
					{
						this.addChild(_symbolSkin);
						_symbolSkin.getBtn.addEventListener(MouseEvent.CLICK,get_Handler);
						//浅入
						fadeIn();
					}
					else
					{
						loadRes();
					}
					break;
				}
				case 7 :
				{
					_symbolSkin = Reflection.createInstance("com.lz.fb.guide.skin.Lv15_Get");
					if(_symbolSkin)
					{
						this.addChild(_symbolSkin);
						_symbolSkin.getBtn.addEventListener(MouseEvent.CLICK,get_Handler);
						//浅入
						fadeIn();
					}
					else
					{
						loadRes();
					}
					break;
				}
			}
		}
		/**
		 *提示 
		 * @param e
		 * 
		 */		
		private function rm_Handler(e :MouseEvent):void
		{
			var lvObj :Object = AppData.getInstance().activityDatemanager.rushLevelObj;
			var clv :int = AppData.getInstance().clubDatamanager.clubInfo.level;
			var isNext :Boolean = false;
			if(showType == 5)
			{
				if(clv==10 && (lvObj.status6==0 || lvObj.status6==1))
				{
					isNext = true;
				}
			}
			else if(showType == 6)
			{
				if(clv==15 && (lvObj.status7==0 || lvObj.status7==1))
				{
					isNext = true;
				}
			}
			else if(showType == 7)
			{
				
			}
			if(isNext)
			{
				showType++;
				showView(showType);
			}
			else
			{
				destroyView();
			}
		}
		/**
		 *领取 
		 * @param e
		 * 
		 */		
		private function get_Handler(e :MouseEvent):void
		{
			AppEventDispatcher.getInstance().dispatchEvent(new ActivityEvent(ActivityEvent.ACTIVITY_LEVEL_AWARD,{id:showType}));
			if(_symbolSkin && _symbolSkin.parent)
			{
				_symbolSkin.parent.removeChild(_symbolSkin);
			}
			var classStrRef :String = "";
			if(showType == 5)
			{
				classStrRef = "com.lz.fb.guide.skin.Lv10_Rm";
			}
			else if(showType == 6)
			{
				classStrRef = "com.lz.fb.guide.skin.Lv15_Rm";
			}
			else if(showType == 7)
			{
				
			}
			_symbolSkin = Reflection.createInstance(classStrRef);
			if(_symbolSkin)
			{
				TweenLite.delayedCall(.5,delayShow);
			}
			else
			{
				destroyView();
			}
		}
		/**
		 *延迟显示 
		 * 
		 */		
		private function delayShow():void
		{
			this.addChild(_symbolSkin);
			_symbolSkin.sureBtn.addEventListener(MouseEvent.CLICK,rm_Handler);
			//浅入
			fadeIn();
		}
		/**
		 *注册事件 
		 * 
		 */		
		public function addEvtListener():void
		{
			this.addEventListener(MouseEvent.MOUSE_MOVE,rollOverH);
		}
		/**
		 * 移上事件 
		 * @param e
		 */	
		private var curTargObj :*;
		private function rollOverH(e:MouseEvent):void
		{
			var tName :String = e.target.name;
			if(curTargObj != e.target)
			{
				curTargObj = e.target;
				if(tName.indexOf("item_")!=-1)
				{
					var tstrArr :Array = tName.split("_");
					var type :int = int(tstrArr[1]);
					var id :int = int(tstrArr[2]);
					var goods :* = AppData.getInstance().goodsManager.getGoodsByTypeAndId(type,id);
					if(goods)
					{
						TipsManager.show(TipsConst.BASETIPS,{tip:goods.tipsInfo},15,15,true,true);
					}
				}
				else
				{
					TipsManager.hide();
				}
			}
		}
		/**
		 *删除事件 
		 * 
		 */		
		public function removeEvtListener():void
		{
			this.removeEventListener(MouseEvent.ROLL_OVER,rollOverH);
		}
		/**
		 *销毁 
		 * 
		 */		
		public function destroyView():void
		{
			AnimationManager.remove();
			removeEvtListener();
			if(this.parent)
			{
				this.parent.removeChild(this);
			}
			if(_symbolSkin && _symbolSkin.sureBtn)
			{
				_symbolSkin.sureBtn.removeEventListener(MouseEvent.CLICK,rm_Handler);
			}
			if(_symbolSkin && _symbolSkin.getBtn)
			{
				_symbolSkin.getBtn.removeEventListener(MouseEvent.CLICK,get_Handler);
			}
		}
	}
}